package cz.muni.fi.pa165.musiclibrary.impl.database.entity;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;


/**
 * Represents a music artist.
 * 
 * @author Maros Kucbel
 * @date 2012-10-11T18:17:21+0200
 */
@Entity
@Table(name="artist")
public class Artist implements IArtist {

    /**
     * Identifier of this artist.
     */
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    @Column(name="id_artist")
    private Long idArtist;
    
    /**
     * Name of this artist.
     */
    @Column(nullable=false)
    private String name;
    
    /**
     * Description of this artist.
     */
    @Column(nullable=true)
    private String description;
    
    @Override
    public Long getIdArtist() {
        return this.idArtist;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public String getDescription() {
        return this.description;
    }
    
    @Override
    public void setIdArtist(@Nonnull final Long idArtist) {
        Validate.isTrue(idArtist != null, "Artist identifier should not be null.");
        this.idArtist = idArtist;
    }

    @Override
    public void setName(@Nonnull final String name) {
        Validate.isTrue(name != null, "Artist's name should not be null.");
        this.name = name;
    }

    @Override
    public void setDescription(@Nullable final String description) {
        this.description = description;
    }

    /**
     * Implemented using {@link EqualsBuilder}.
     * 
     * {@inheritDoc }
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj == null || !(obj instanceof IArtist)) {
            return false;
        }
        
        final IArtist other = (IArtist) obj;
        return new EqualsBuilder()//
                .append(this.getIdArtist(), other.getIdArtist())//
                .build();
    }
    
    /**
     * Implemented using {@link HashCodeBuilder}.
     * 
     * {@inheritDoc }.
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder()//
                .append(this.getIdArtist())//
                .build();
    }

    /**
     * Implemented using {@link ToStringBuilder#reflectionToString(java.lang.Object, org.apache.commons.lang3.builder.ToStringStyle) }
     * with second argument {@link ToStringStyle#MULTI_LINE_STYLE}.
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
    
}